<template>
  <div>
    <el-row ref="search_form">
          <el-col :span="24">
            <div class="search-box">
              <el-form :inline="true" size="medium" :model="searchForm">


                <el-form-item label="">
                  <el-select v-model="searchForm.carEnterpriseId" size="mini" placeholder="请选择车企" clearable>
                    <el-option v-for="item in carEntList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="">
                  <el-select v-model="searchForm.carTypeId" size="mini" placeholder="请选择车型类别" clearable>
                    <el-option v-for="item in carTypeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="">
                  <el-select v-model="searchForm.productTypeIds" size="mini" placeholder="请选择申报类型" clearable>
                    <el-option v-for="item in testProductTypeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="">
                  <el-select v-model="searchForm.customerName" size="mini" placeholder="请选择业务经理" clearable>
                    <el-option v-for="item in customerNameList" :key="item.id" :label="item.name" :value="item.name"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label=""  v-if="this.userRole != 7">
                  <el-select v-model="searchForm.closingPayPrice" size="mini" placeholder="是否结算" clearable>
                    <el-option :key="1" label="未结算" :value="0"></el-option>
                    <el-option :key="2" label="已结算" :value="1"></el-option>

                  </el-select>
                </el-form-item>

                <el-form-item label="" v-if="this.userRole != 7">
                  <el-select v-model="searchForm.closingCost" size="mini" placeholder="是否支付" clearable>
                    <el-option :key="1" label="未支付" :value="0"></el-option>
                    <el-option :key="2" label="已支付" :value="1"></el-option>
                  </el-select>
                </el-form-item>





                <el-form-item>
                  <el-button  size="mini" type="primary" @click="search">查询</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button  size="mini" type="primary" @click="clear">清空</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button  size="mini" type="primary" @click="search">刷新</el-button>
                </el-form-item>

                <el-form-item v-if="this.userRole != 7&&this.userRole != 8">
                  <el-button type="primary" @click="settlement" size="mini">结算</el-button>
                </el-form-item>
                <el-form-item v-if="this.userRole != 7&&this.userRole != 8">
                  <el-button type="primary" @click="pay" size="mini">支付</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" size="mini" @click="exportExcel">Excel导出</el-button>
                </el-form-item>


              </el-form>
            </div>
          </el-col>
        </el-row>


    <el-table v-if="this.userRole == 8"
      :data="tableData"
      :header-cell-style="{backgroundColor:'#f4f4f5',textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      :height="tableHeight"
      border
      @selection-change="handleSelectionChange"
      style="width: 100%">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="id"
        label="序号"
        type="index"
        width="80">
      </el-table-column>
      <el-table-column
        prop="itemCode"
        label="任务编码"
        min-width="140">
      </el-table-column>
      <el-table-column
        prop="carEnterpriseName"
        label="车企"
        min-width="120">
      </el-table-column>
      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="customerName"
        label="业务经理"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="name"
        label="产品名称"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="model"
        label="产品型号"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="productTypeName"
        label="申报类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName1+"/"+scope.row.productTypeName2}}
        </template>
      </el-table-column>
      <el-table-column
        prop="serialNumber"
        label="检测项目统计"
        min-width="120">
        <template scope="scope">
            {{serialNumber(scope.row.serialNumber,scope.row.itemNum,scope.row.itemList)}}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          {{orderStatus(scope.row.orderStatus)}}
        </template>
      </el-table-column>

      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="customerName"
        label="客户名称"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="orgName"
        label="检测机构"
        min-width="120">
      </el-table-column> -->

      <!-- <el-table-column
        prop="productTypeName"
        label="产品类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName+"/"+scope.row.parentProductTypeName}}
          <template v-if="scope.row.hasDx">+定型</template>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="testItems"
        label="检测项目"
        min-width="170">
        <template scope="scope">
          <span v-html="parseTestItem2(scope.row)"></span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="rebate"
        label="默认折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.rebate}}%
        </template>
      </el-table-column>
      <el-table-column
        prop="siteRebate"
        label="默认场地折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.siteRebate}}%
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="priceCost"
        label="成本总价"
        min-width="120">
        <template scope="scope">
          {{priceCost(scope.row.priceCost,scope.row.amount)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="payPriceCost"
        label="实际支付成本"
        min-width="120">
        <template scope="scope">
          {{payPriceCost(scope.row.priceCost,scope.row.payPriceCost,scope.row.amount)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="closingCost"
        label="成本费是否支付"
        min-width="120">
        <template scope="scope">
          {{closings(scope.row.closingCost)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="price"
        label="总报价"
        min-width="120">
        <template scope="scope">
          {{payPrice(scope.row.price,scope.row.amountPay)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="payPrice"
        label="实际收款"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="closingPayPrice"
        label="是否结算费用"
        min-width="120">
        <template scope="scope">
          {{closing(scope.row.closingPayPrice)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="amount"
        label="其他费用(成本)"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="amountPay"
        label="其他费用(报价)"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="nums"
        label="报告份数"
        min-width="120">
        <template scope="scope">
          {{num(scope.row.nums,scope.row.productTypeId,scope.row.numList)}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="isSend"
        label="是否送样"
        min-width="100">
        <template scope="scope">
          {{scope.row.isSend?"是":"否"}}
        </template>
      </el-table-column> -->


      <!-- <el-table-column
        prop="id"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.step == 0">未下发</span>
          <span v-if="scope.row.step == 1">已完成</span>
          <span v-if="scope.row.step == 2">工程师A</span>
          <span v-if="scope.row.step == 3">工程师B</span>
          <span v-if="scope.row.step == 4">工程师C</span>
          <span v-if="scope.row.stepStatus == 3">(回退)</span>
          <span v-if="scope.row.stepStatus == 4">(转交)</span>
        </template>
      </el-table-column> -->

      <el-table-column
        prop="updateTime"
        label="最后修改时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.updateTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.createTime)}}
        </template>
      </el-table-column>

      <el-table-column
        prop="note"
        label="备注"
        min-width="160">
      </el-table-column>
      <el-table-column
        prop="address"
        fixed="right"
        label="操作"
        min-width="250">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button> -->
          <el-button style="margin-top:8px" size="mini" type="primary" @click="updateLog(scope.$index, scope.row)">操作日志</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleShowTask(scope.$index, scope.row)">查看任务</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">实验任务跟踪</el-button>
          <template v-if="scope.row.orderStatus != 1">
            <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderDone(scope.$index, scope.row)">任务单完成</el-button> -->
          </template>
          <!-- <template >
            <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEdit(scope.$index, scope.row)">修改</el-button>
          </template> -->
          <!-- <template v-if="scope.row.step == 0">
            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
          <template v-if="scope.row.step == 1||scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleShowData(scope.$index, scope.row)">数据</el-button>
          </template>
          <template v-if="scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleToUser(scope.$index, scope.row)">转交</el-button>
          </template> -->
        </template>
      </el-table-column>

    </el-table>

    <el-table v-if="this.userRole == 7"
      :data="tableData"
      :header-cell-style="{backgroundColor:'#f4f4f5',textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      :height="tableHeight"
      border
      @selection-change="handleSelectionChange"
      style="width: 100%">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="id"
        label="序号"
        type="index"
        width="80">
      </el-table-column>
      <el-table-column
        prop="itemCode"
        label="任务编码"
        min-width="140">
      </el-table-column>
      <el-table-column
        prop="carEnterpriseName"
        label="车企"
        min-width="120">
      </el-table-column>
      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="customerName"
        label="业务经理"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="name"
        label="产品名称"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="model"
        label="产品型号"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="productTypeName"
        label="申报类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName1+"/"+scope.row.productTypeName2}}
        </template>
      </el-table-column>
      <el-table-column
        prop="serialNumber"
        label="检测项目统计"
        min-width="120">
        <template scope="scope">
            {{serialNumber(scope.row.serialNumber,scope.row.itemNum,scope.row.itemList)}}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          {{orderStatus(scope.row.orderStatus)}}
        </template>
      </el-table-column>

      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="customerName"
        label="客户名称"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="orgName"
        label="检测机构"
        min-width="120">
      </el-table-column> -->

      <!-- <el-table-column
        prop="productTypeName"
        label="产品类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName+"/"+scope.row.parentProductTypeName}}
          <template v-if="scope.row.hasDx">+定型</template>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="testItems"
        label="检测项目"
        min-width="170">
        <template scope="scope">
          <span v-html="parseTestItem2(scope.row)"></span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="rebate"
        label="默认折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.rebate}}%
        </template>
      </el-table-column>
      <el-table-column
        prop="siteRebate"
        label="默认场地折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.siteRebate}}%
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="priceCost"
        label="成本总价"
        min-width="120">
        <template scope="scope">
          {{priceCost(scope.row.priceCost,scope.row.amount)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="payPriceCost"
        label="实际支付成本"
        min-width="120">
        <template scope="scope">
          {{payPriceCost(scope.row.priceCost,scope.row.payPriceCost,scope.row.amount)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="closingCost"
        label="成本费是否支付"
        min-width="120">
        <template scope="scope">
          {{closings(scope.row.closingCost)}}
        </template>
      </el-table-column> -->
      <el-table-column
        prop="price"
        label="总报价"
        min-width="120">
        <template scope="scope">
          {{payPrice(scope.row.price,scope.row.amountPay,scope.row.note)}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="payPrice"
        label="实际收款"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="closingPayPrice"
        label="是否结算费用"
        min-width="120">
        <template scope="scope">
          {{closing(scope.row.closingPayPrice)}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        prop="amount"
        label="其他费用(成本)"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="amountPay"
        label="其他费用(报价)"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="nums"
        label="报告份数"
        min-width="120">
        <template scope="scope">
          {{num(scope.row.nums,scope.row.productTypeId,scope.row.numList)}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="isSend"
        label="是否送样"
        min-width="100">
        <template scope="scope">
          {{scope.row.isSend?"是":"否"}}
        </template>
      </el-table-column> -->


      <!-- <el-table-column
        prop="id"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.step == 0">未下发</span>
          <span v-if="scope.row.step == 1">已完成</span>
          <span v-if="scope.row.step == 2">工程师A</span>
          <span v-if="scope.row.step == 3">工程师B</span>
          <span v-if="scope.row.step == 4">工程师C</span>
          <span v-if="scope.row.stepStatus == 3">(回退)</span>
          <span v-if="scope.row.stepStatus == 4">(转交)</span>
        </template>
      </el-table-column> -->

      <el-table-column
        prop="updateTime"
        label="最后修改时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.updateTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.createTime)}}
        </template>
      </el-table-column>

      <el-table-column
        prop="note"
        label="备注"
        min-width="160">
        <template scope="scope">
          {{scope.row.note}}
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        fixed="right"
        label="操作"
        min-width="250">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button> -->
          <el-button style="margin-top:8px" size="mini" type="primary" @click="updateLog(scope.$index, scope.row)">操作日志</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleShowTask(scope.$index, scope.row)">查看任务</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">实验任务跟踪</el-button>
          <template v-if="scope.row.orderStatus != 1">
            <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderDone(scope.$index, scope.row)">任务单完成</el-button> -->
          </template>
          <!-- <template >
            <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEdit(scope.$index, scope.row)">修改</el-button>
          </template> -->
          <!-- <template v-if="scope.row.step == 0">
            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
          <template v-if="scope.row.step == 1||scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleShowData(scope.$index, scope.row)">数据</el-button>
          </template>
          <template v-if="scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleToUser(scope.$index, scope.row)">转交</el-button>
          </template> -->
        </template>
      </el-table-column>

    </el-table>




    <el-table v-if="this.userRole != 7&&this.userRole != 8"
      :data="tableData"
      :header-cell-style="{backgroundColor:'#f4f4f5',textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      :height="tableHeight"
      border
      @selection-change="handleSelectionChange"
      style="width: 100%">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="id"
        label="序号"
        type="index"
        width="80">
      </el-table-column>
      <el-table-column
        prop="itemCode"
        label="任务编码"
        min-width="140">
      </el-table-column>
      <el-table-column
        prop="carEnterpriseName"
        label="车企"
        min-width="120">
      </el-table-column>
      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="customerName"
        label="业务经理"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="name"
        label="产品名称"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="model"
        label="产品型号"
        min-width="120">
        <!-- <template scope="scope">

          {{nameModel(scope.row.name,scope.row.model)}}
        </template> -->
      </el-table-column>

      <el-table-column
        prop="productTypeName"
        label="申报类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName1+"/"+scope.row.productTypeName2}}
        </template>
      </el-table-column>
      <el-table-column
        prop="serialNumber"
        label="检测项目统计"
        min-width="120">
        <template scope="scope">
            {{serialNumber(scope.row.serialNumber,scope.row.itemNum,scope.row.itemList)}}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          {{orderStatus(scope.row.orderStatus)}}
        </template>
      </el-table-column>

      <!-- <el-table-column
        prop="brand"
        label="车企商标"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="customerName"
        label="客户名称"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="orgName"
        label="检测机构"
        min-width="120">
      </el-table-column> -->

      <!-- <el-table-column
        prop="productTypeName"
        label="产品类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName+"/"+scope.row.parentProductTypeName}}
          <template v-if="scope.row.hasDx">+定型</template>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="testItems"
        label="检测项目"
        min-width="170">
        <template scope="scope">
          <span v-html="parseTestItem2(scope.row)"></span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column
        prop="rebate"
        label="默认折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.rebate}}%
        </template>
      </el-table-column>
      <el-table-column
        prop="siteRebate"
        label="默认场地折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.siteRebate}}%
        </template>
      </el-table-column> -->
      <el-table-column
        prop="priceItemCost"
        label="检测费成本"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.priceItemCost).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="priceSiteCost"
        label="场地费成本"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.priceSiteCost).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="amount"
        label="其他费用成本"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.amount).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="interiorAmount"
        label="内部费用成本"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.interiorAmount).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="priceCost"
        label="成本总价"
        min-width="120">
        <template scope="scope">
          {{priceCost(scope.row.priceCost,scope.row.amount,scope.row.interiorAmount)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="payPriceCost"
        label="实际支付成本"
        min-width="120">
        <template scope="scope">
          {{payPriceCost(scope.row.priceCost,scope.row.payPriceCost,scope.row.amount,scope.row.interiorAmount)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="closingCost"
        label="成本费是否支付"
        min-width="120">
        <template scope="scope">
          {{closings(scope.row.closingCost)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="priceItemPay"
        label="检测费报价"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.priceItemPay).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="priceSitePay"
        label="场地费报价"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.priceSitePay).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="amountPay"
        label="其他费用报价"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.amountPay).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="interiorAmountPay"
        label="内部费用报价"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.interiorAmountPay).toFixed(2)}}
        </template>
      </el-table-column>

      <el-table-column
        prop="price"
        label="总报价"
        min-width="120">
        <template scope="scope">
          {{payPrice(scope.row.price,scope.row.amountPay,scope.row.note,scope.row.interiorAmountPay)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="payPrice"
        label="实际收款"
        min-width="120">
        <template scope="scope">
          {{parseFloat(scope.row.payPrice).toFixed(2)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="closingPayPrice"
        label="是否结算费用"
        min-width="120">
        <template scope="scope">
          {{closing(scope.row.closingPayPrice)}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="amount"
        label="其他费用(成本)"
        min-width="120">
      </el-table-column> -->
      <!-- <el-table-column
        prop="amountPay"
        label="其他费用(报价)"
        min-width="120">
      </el-table-column> -->
      <el-table-column
        prop="nums"
        label="报告份数"
        min-width="120">
        <template scope="scope">
          {{num(scope.row.nums,scope.row.productTypeId,scope.row.numList)}}
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="isSend"
        label="是否送样"
        min-width="100">
        <template scope="scope">
          {{scope.row.isSend?"是":"否"}}
        </template>
      </el-table-column> -->


      <!-- <el-table-column
        prop="id"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.step == 0">未下发</span>
          <span v-if="scope.row.step == 1">已完成</span>
          <span v-if="scope.row.step == 2">工程师A</span>
          <span v-if="scope.row.step == 3">工程师B</span>
          <span v-if="scope.row.step == 4">工程师C</span>
          <span v-if="scope.row.stepStatus == 3">(回退)</span>
          <span v-if="scope.row.stepStatus == 4">(转交)</span>
        </template>
      </el-table-column> -->

      <el-table-column
        prop="updateTime"
        label="最后修改时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.updateTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.createTime)}}
        </template>
      </el-table-column>

      <el-table-column
        prop="note"
        label="备注"
        min-width="160">
      </el-table-column>

      <el-table-column v-if = "this.userRole == 1"
        prop="address"
        fixed="right"
        label="操作"
        min-width="250">
        <template slot-scope="scope">
          <template v-if="scope.row.excel==0">
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button>

          <el-button style="margin-top:8px" size="mini" type="primary" @click="updateLog(scope.$index, scope.row)">操作日志</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleShowTask(scope.$index, scope.row)">查看任务</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">实验任务跟踪</el-button>

            <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderDone(scope.$index, scope.row)">任务单完成</el-button> -->

            <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEdit(scope.$index, scope.row)">修改</el-button>
            </template>


            <template v-if="scope.row.excel!=0">
              <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEditExcel(scope.$index, scope.row)">修改</el-button>
              <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button>
            </template>
            <el-button style="margin-top:8px" size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>


          <!-- <template v-if="scope.row.step == 0">
            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
          <template v-if="scope.row.step == 1||scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleShowData(scope.$index, scope.row)">数据</el-button>
          </template>
          <template v-if="scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleToUser(scope.$index, scope.row)">转交</el-button>
          </template> -->
        </template>

      </el-table-column>

      <el-table-column v-if = "this.userRole = 5"
        prop="address"
        fixed="right"
        label="操作"
        min-width="250">
        <template slot-scope="scope">
          <template v-if="scope.row.excel==0">
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button>

          <el-button style="margin-top:8px" size="mini" type="primary" @click="updateLog(scope.$index, scope.row)">操作日志</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleShowTask(scope.$index, scope.row)">查看任务</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">实验任务跟踪</el-button>

            <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderDone(scope.$index, scope.row)">任务单完成</el-button> -->

            <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEdit(scope.$index, scope.row)">修改</el-button>
            </template>


            <template v-if="scope.row.excel!=0">
              <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEditExcel(scope.$index, scope.row)">修改</el-button>
              <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button>
            </template>



          <!-- <template v-if="scope.row.step == 0">
            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
          <template v-if="scope.row.step == 1||scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleShowData(scope.$index, scope.row)">数据</el-button>
          </template>
          <template v-if="scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleToUser(scope.$index, scope.row)">转交</el-button>
          </template> -->
        </template>

      </el-table-column>

      <el-table-column v-if = "this.userRole != 1 &&this.userRole != 5"
        prop="address"
        fixed="right"
        label="操作"
        min-width="250">
        <template slot-scope="scope">
          <template v-if="scope.row.excel==0">
          <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button> -->

          <el-button style="margin-top:8px" size="mini" type="primary" @click="updateLog(scope.$index, scope.row)">操作日志</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleShowTask(scope.$index, scope.row)">查看任务</el-button>
          <el-button style="margin-top:8px" size="mini" type="primary" @click="handleTaskDone(scope.$index, scope.row)">实验任务跟踪</el-button>

            <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderDone(scope.$index, scope.row)">任务单完成</el-button> -->

            <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEdit(scope.$index, scope.row)">修改</el-button>
            </template>


            <template v-if="scope.row.excel!=0">
              <el-button style="margin-top:8px" size="mini" type="primary" @click="handleOrderEditExcel(scope.$index, scope.row)">修改</el-button>
              <!-- <el-button style="margin-top:8px" size="mini" type="primary" @click="handlePriceOtherManage(scope.$index, scope.row)">其他费用管理</el-button> -->
            </template>



          <!-- <template v-if="scope.row.step == 0">
            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
          <template v-if="scope.row.step == 1||scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleShowData(scope.$index, scope.row)">数据</el-button>
          </template>
          <template v-if="scope.row.step == 2||scope.row.step == 3||scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleToUser(scope.$index, scope.row)">转交</el-button>
          </template> -->
        </template>

      </el-table-column>


    </el-table>
    <div class="block">
       <span class="demonstration"></span>
       <el-pagination
         @size-change="handleSizeChange"
         @current-change="handleCurrentChange"
         :current-page="currentPage"
         :page-sizes="[10, 20, 50, 100,200]"
         :page-size="pageSize"
         layout="total, sizes, prev, pager, next, jumper"
         :total="total">
       </el-pagination>
     </div>

     <el-dialog title="关联任务" :visible.sync="doneFormVisible" width="700px" :close-on-click-modal="false">

         <el-row>
           <el-col :span="24">
             <table class="test-item-table">
               <tr>
                 <th>申报类型</th>
                 <th>项目代号</th>
                 <th>检测项目</th>
                 <th>数量</th>
                 <th>检测机构</th>
                 <th>
                   是否完成
                   <!-- <el-button type="primary" size="mini" ></el-button> -->
                 </th>
               </tr>

               <tr v-for="(item,index) in taskItems">
                 <td>{{item.name +'/'+item.name1}}</td>
                 <td>{{item.serialNumber}}</td>
                 <td>{{item.itemName}}</td>
                 <td>{{item.num}}</td>
                 <td>{{item.orgName}}</td>
                 <td>
                   <input v-model="doneForm.doneTaskItemIds" type="checkbox" :value="item.id" disabled="disabled">
                 </td>
               </tr>

             </table>
           </el-col>
         </el-row>

       <div slot="footer" class="dialog-footer" style="margin-top: 20px;">
         <el-button @click="doneFormVisible = false">取 消</el-button>
         <!-- <el-button type="primary" @click.native.prevent="submitDoneSave">保存</el-button>
         <el-button type="primary" @click.native.prevent="submitDoneNext">提交</el-button> -->
       </div>
     </el-dialog>



    <el-dialog :title="editForm.id==0?'新增':'修改'" :visible.sync="editFormVisible" width="80%" top="5vh" :close-on-click-modal="false">
      <el-form :model="editForm" ref="editForm" :rules="editRules">
        <el-row>
          <el-col :span="12">
            <el-form-item label="车企" label-width="100px" prop="carEnterpriseId">
              <el-select v-model="editForm.carEnterpriseId" placeholder="请选择" style="width: 100%;" :disabled="carEntDisabled" @change="onCarEntChange()">
                <el-option
                  v-for="item in carEntList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
              <!-- <el-button type="primary" icon="el-icon-refresh" circle style="margin-left: 10px;" @click="refreshCarEntList"></el-button>
              <el-button type="primary" icon="el-icon-edit" circle style="margin-left: 10px;" @click="handlerOpenPage(1)"></el-button> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="商标" label-width="100px" prop="brand">
            <el-input v-model="editForm.brand" controls-position="right" :min="0" style="width: 100%;" disabled></el-input>
          </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="车型类别" label-width="100px" prop="carTypeId" >
              <el-select v-model="editForm.carTypeId" placeholder="请选择"  :disabled="editForm.id==0?false:true" style="width: 100%;" @change="onCarTypeChange()">
                <el-option
                  v-for="item in carTypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="申报类型" label-width="100px" prop="productTypeIds" >
              <el-cascader  style="width: 100%;" :disabled="editForm.id==0?false:true"
                  v-model="editForm.productTypeIds"
                  :options="testProductTypeList"
                  :props="{ expandTrigger: 'click', value: 'id', label: 'name' }"
                  @change="onProductTypeChange"
                  ></el-cascader>
            </el-form-item>
          </el-col>

        </el-row>


        <el-row>
        <el-col :span="12">
        <el-form-item label="业务经理" label-width="100px" prop="customerName">
          <el-select v-model="editForm.customerName"   placeholder="请选择" style="width: 45%;"  :disabled="editForm.id==0?false:true">
              <el-option
                v-for="item in customerNameList"
                :key="item.id"
                :label="item.name"
                :value="item.name">
              </el-option>
            </el-select>
        </el-form-item>
        </el-col>

        <el-col :span="5">
        <el-form-item label="产品名称" label-width="100px" prop="name">
          <el-input v-model="editForm.name" autocomplete="off" :disabled="editForm.id==0?false:true" ></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="5">
        <el-form-item label="产品型号" label-width="100px" prop="model">
          <el-input v-model="editForm.model" autocomplete="off" :disabled="editForm.id==0?false:true" ></el-input>
        </el-form-item>
        </el-col>
        </el-row>


        <el-row>
        <el-col :span="6">
        <el-form-item label="建议完成时间" label-width="100px" prop="suggestTime" >
          <el-date-picker
                v-model="editForm.suggestTime"  :disabled="editForm.id==0?false:true"
                type="datetime"
                value-format="timestamp"
                placeholder="选择日期时间">
              </el-date-picker>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="是否重要车型" label-width="150px" prop="importance">
          <el-select v-model="editForm.importance" placeholder="请选择"  :disabled="editForm.id==0?false:true">
            <el-option :key="1" label="是" :value="1"></el-option>
            <el-option :key="2" label="否" :value="2"></el-option>
          </el-select>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="原因" label-width="100px" prop="cause">
          <el-input v-model="editForm.cause" autocomplete="off"  :disabled="editForm.id==0?false:true"></el-input>
        </el-form-item>
        </el-col>
        </el-row>

          <!-- <el-row>
          <el-col :span="5">

          </el-col>
          </el-row> -->


        <el-row>
          <el-col :span="24">
            <el-form-item label="检测任务" label-width="100px" prop="testTasks">
              <!-- <el-button size="mini" type="primary" @click="showAddOrderTask()">增加检测任务</el-button> -->
              <table class="test-item-table">
                <tr>
                  <th>VIN</th>
                  <th>检测产品类别</th>
                  <th>检测费</th>
                  <th>场地费</th>
                  <th>检测费(成本)</th>
                  <th>场地费(成本)</th>
                  <th>&nbsp;</th>
                </tr>
                <tr v-for="(item,index) in editForm.testTasks">
                  <td>{{item.vin}}</td>
                  <td>{{item.productTypeName1}}/{{item.productTypeName2}}</td>
                  <td>{{item.priceItemPay}}</td>
                  <td>{{item.priceSitePay}}</td>
                  <td>{{item.priceItemCost}}</td>
                  <td>{{item.priceSiteCost}}</td>
                  <td>
                    <el-button type="primary" size="mini" @click="onTaskEditClick(index)">查看</el-button>
                    <!-- <el-button type="warning" size="mini" @click="removeOrderTask(index)">删除</el-button> -->
                  </td>
                </tr>
              </table>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="editForm.productTypeId1">
          <el-col :span="24">
            <div class="chose-role">
              <span style="color:red">*</span>检测方案核定-A:
              <el-select v-model="editForm.a" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userListAB" :key="item.id" :label="item.nickname" :value="item.id"></el-option>
              </el-select>
            </div>
            <div class="chose-role">
              <span style="color:red">*</span> 参 数 填 报 - B:
              <el-select v-model="editForm.b" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userListAB" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div>
            <div class="chose-role">
              <span style="color:red">*</span>方案参数审核-C:
              <el-select v-model="editForm.c" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userListC" :key="item.id" :label="item.nickname" :value="item.id"></el-option>
              </el-select>
            </div>
            <div class="chose-role">
              <span style="color:red">*</span> 报 告 出 具 - D:
              <el-select v-model="editForm.d" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userListD" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div>
            <div class="chose-role">
              <span style="color:red">* </span> 报 告 审 核 - E:
              <el-select v-model="editForm.e" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userListE" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div>
            <div class="chose-role">
              <span style="color:red">*</span> 批  准 ——— F:
              <el-select v-model="editForm.f" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div>
            <div class="chose-role" v-if="editForm.productTypeId1 == 1 || editForm.productTypeId1 == 2 ">
              <span style="color:red">*</span> 原 始 记 录 - G:
              <el-select v-model="editForm.g" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"></el-option>
              </el-select>
            </div>
            <div class="chose-role" v-if="editForm.productTypeId1 == 1 || editForm.productTypeId1 == 2">
              <span style="color:red">*</span>提交及追踪-H:
              <el-select v-model="editForm.h" placeholder="请选择" size="mini" @change="onUserHChange(editForm.h)"  :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div>
            <!-- <div class="chose-role" v-if="editTaskForm.productTypeId1 == 1">
              <span style="color:red">*</span>检测机构已提交-I:
              <el-select v-model="editTaskForm.i" placeholder="请选择" size="mini">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option>
              </el-select>
            </div> -->
            <!-- <div class="chose-role" v-if="editTaskForm.productTypeId1 == 2">
              <span style="color:red">*</span>检测报告生成-J:
              <el-select v-model="editTaskForm.j" placeholder="请选择" size="mini">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div> -->
            <div class="chose-role" v-if="editForm.productTypeId1 == 3 || editForm.productTypeId1 == 4|| editForm.productTypeId1 == 19 ">
              <span style="color:red">*</span> 企 业 提 交 - K :
              <el-select v-model="editForm.k" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div>
            <div class="chose-role" v-if="editForm.productTypeId1 == 3">
              <span style="color:red">*</span> 原 始 记 录 - G :
              <el-select v-model="editForm.g" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"></el-option>
              </el-select>
            </div>
            <!-- <div class="chose-role" v-if="editTaskForm.productTypeId1 == 2">
              <span style="color:red">*</span> 反  馈 ——— L :
              <el-select v-model="editTaskForm.l" placeholder="请选择" size="mini">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div>
            <div class="chose-role" v-if="editTaskForm.productTypeId1 == 2">
              <span style="color:red">*</span> 反 馈 提 交 - M :
              <el-select v-model="editTaskForm.m" placeholder="请选择" size="mini">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div>
            <div class="chose-role" v-if="editTaskForm.productTypeId1 == 2">
              <span style="color:red">*</span> 审 核 通 过 - N:
              <el-select v-model="editTaskForm.n" placeholder="请选择" size="mini">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div> -->
            <div class="chose-role" v-if="editForm.productTypeId1 == 19">
              <span style="color:red">*</span> 客 户 确 认 - O:
              <el-select v-model="editForm.o" placeholder="请选择" size="mini" :disabled="editForm.id==0?false:true">
                <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"> </el-option></el-select>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="成本总价" label-width="100px" prop="priceCost">
              <el-input v-model="editForm.priceCost" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际支付" label-width="100px" prop="price">
              <el-input-number v-model="editForm.payPriceCost" controls-position="right" :min="0" style="width: 100%;" @change="onPayPriceCost"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总报价" label-width="100px" prop="price">
              <el-input v-model="editForm.price" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际收款" label-width="100px" prop="price">
              <el-input-number v-model="editForm.payPrice" controls-position="right" :min="0" style="width: 100%;" @change="onPayPriceChange"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" label-width="100px">
          <el-input v-model="editForm.note" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitForm" :loading="loading">保存</el-button>
        <!-- <el-button type="success" @click.native.prevent="submitFormNext" :loading="loading">下发任务</el-button> -->
      </div>
    </el-dialog>



    <el-dialog :title="editForm.id==0?'新增':'修改'" :visible.sync="excleVisible" width="80%" top="5vh" :close-on-click-modal="false">
      <el-form :model="editForm" ref="editForm" :rules="editRules">

        <el-row>
          <el-col :span="12">
            <el-form-item label="成本总价" label-width="100px" prop="priceCost">
              <el-input v-model="editForm.priceCost" type="number" autocomplete="off" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际支付" label-width="100px" prop="price">
              <el-input-number v-model="editForm.payPriceCost" controls-position="right" :min="0" style="width: 100%;" ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总报价" label-width="100px" prop="price">
              <el-input v-model="editForm.price" type="number" autocomplete="off" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际收款" label-width="100px" prop="price">
              <el-input-number v-model="editForm.payPrice" controls-position="right" :min="0" style="width: 100%;" ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" label-width="100px">
          <el-input v-model="editForm.note" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="excleVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitFormExcle" :loading="loading">保存</el-button>
        <!-- <el-button type="success" @click.native.prevent="submitFormNext" :loading="loading">下发任务</el-button> -->
      </div>
    </el-dialog>

    <!-- 添加检测任务 -->
    <el-dialog :visible.sync="showEditTaskDialog" width="80%" top="5vh" >
      <el-form :model="editTaskForm" ref="editTaskForm" :rules="editTaskRules">
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="车型类别" label-width="100px" prop="carTypeId">
              <el-select v-model="editTaskForm.carTypeId" placeholder="请选择" style="width: 100%;" @change="onCarTypeChange()">
                <el-option
                  v-for="item in carTypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="6">
          <el-form-item label="产品名称" label-width="100px" prop="name">
            <el-input v-model="editTaskForm.name" autocomplete="off" :disabled="carEntDisableds"></el-input>
          </el-form-item>
          </el-col>
          <el-col :span="6">
          <el-form-item label="产品型号" label-width="100px" prop="model">
            <el-input v-model="editTaskForm.model" autocomplete="off" :disabled="carEntDisableds"></el-input>
          </el-form-item>
          </el-col> -->
          <el-col :span="6">
          <el-form-item label="VIN" label-width="100px" prop="vin">
            <el-input v-model="editTaskForm.vin" autocomplete="off" :disabled="carEntDisableds"></el-input>
          </el-form-item>
          </el-col>
          <el-col :span="6">
          <el-form-item label="生产年月" label-width="100px" prop="prDate" >
            <el-date-picker :disabled="carEntDisableds"
              v-model="editTaskForm.prDate"
              type="month"
              value-format="timestamp"
              format="yyyy年MM月"
              placeholder="选择生产年月">
            </el-date-picker>
          </el-form-item>
          </el-col>
          <el-col :span="6">
          <el-form-item label="颜色" label-width="100px" prop="color">
            <el-input v-model="editTaskForm.color" autocomplete="off" :disabled="carEntDisableds"></el-input>
          </el-form-item>
          </el-col>
          <el-col :span="6">
          <el-form-item label="是否送样" label-width="100px" prop="sendSample" >
            <el-select v-model="editTaskForm.sendSample" placeholder="请选择"  :disabled="carEntDisableds">
              <el-option :key="1" label="是" :value="1"></el-option>
              <el-option :key="2" label="否" :value="2"></el-option>
            </el-select>
          </el-form-item>
          </el-col>
        </el-row>
        <el-row>

        <el-col :span="12">
          <el-form-item label="收车人" label-width="100px" prop="carPeople" v-if="editTaskForm.sendSample==1">
            <el-select v-model="editTaskForm.carPeople"  multiple placeholder="请选择" style="width: 100%;" :disabled="editForm.id==0?false:true">
              <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          </el-col>

          <el-col :span="6">
          <el-form-item label="收车人备注" label-width="100px" prop="carPeopleNote" v-if="editTaskForm.sendSample==1">
            <el-input v-model="editTaskForm.carPeopleNote" autocomplete="off"  :disabled="carEntDisableds"></el-input>
          </el-form-item>
          </el-col>

          <el-col :span="6">
          <el-form-item label="拟送样时间" label-width="100px" prop="sendSampleTime" v-if="editTaskForm.sendSample==1" >
            <el-date-picker
                  v-model="editTaskForm.sendSampleTime" :disabled="editForm.id==0?false:true"
                  type="datetime"
                  value-format="timestamp"
                  placeholder="选择送样时间">
                </el-date-picker>
          </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="申报类型" label-width="100px" prop="productTypeIds">
              <el-cascader  style="width: 100%;"
                  v-model="editTaskForm.productTypeIds"
                  :options="testProductTypeList"
                  :props="{ expandTrigger: 'click', value: 'id', label: 'name' }"
                  @change="onProductTypeChange"
                  ></el-cascader>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
          <el-form-item label="无任务车辆" label-width="100px" prop="carId" v-if="editTaskForm.sendSample==null||editTaskForm.sendSample==''||editTaskForm.sendSample==2">
            <el-select v-model="editTaskForm.carId"   placeholder="请选择" style="width: 100%;"  :disabled="editForm.id==0?false:true"
            @change="carVin">
                <el-option
                  v-for="item in carVinList"
                  :key="item.id"
                  :label="item.name+'-'+item.model+'-VIN:'+item.vin"
                  :value="item.id">
                </el-option>
              </el-select>
          </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="检测场地" label-width="100px" prop="siteId">
              <el-select v-model="editTaskForm.siteId " placeholder="请选择" style="width: 100%;" @change="computeTaskPrice()"  :disabled="editForm.id==0?false:true">
                <el-option
                  v-for="item in testSiteList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检测机构" label-width="100px" prop="orgId">
              <el-select v-model="editTaskForm.orgId" placeholder="请选择" style="width: 100%;"  :disabled="editForm.id==0?false:true">
                <el-option
                  v-for="item in orgList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="打包项目" label-width="100px" prop="groupId">
              <el-select v-model="editTaskForm.groupId" placeholder="请选择" style="width: 100%;" clearable  @change="onGroupChange" @clear="GroupChange"  :disabled="editForm.id==0?false:true">
                <el-option
                  v-for="item in groupList"
                  :key="item.id"
                  :label="item.name + '(¥'+item.price+')'"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <!-- <el-row>
        <el-col :span="6">
        <el-form-item label="建议完成时间" label-width="100px" prop="suggestTime">
          <el-date-picker
                v-model="editTaskForm.suggestTime"
                type="datetime"
                value-format="timestamp"
                placeholder="选择日期时间">
              </el-date-picker>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="是否重要车型" label-width="110px" prop="importance">
          <el-select v-model="editTaskForm.importance" placeholder="请选择">
            <el-option :key="1" label="是" :value="1"></el-option>
            <el-option :key="2" label="否" :value="2"></el-option>
          </el-select>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="原因" label-width="100px" prop="cause">
          <el-input v-model="editTaskForm.cause" autocomplete="off"></el-input>
        </el-form-item>
        </el-col>
        </el-row> -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="检测项目" label-width="100px" prop="testItems">
              <!-- <el-button size="mini" type="primary" @click="showChoseItemDialog()">增加项目</el-button> -->
              <table class="test-item-table">
                <tr>
                  <th>项目代码</th>
                  <th>检测项目</th>
                  <th>单价</th>
                  <th>场地费</th>
                  <th>数量</th>
                  <th>折扣</th>
                  <th>价格</th>
                  <th>场地折扣</th>
                  <th>场地价格</th>
                  <th>成本折扣</th>
                  <th>成本</th>

                  <th>场地成本价格</th>
                  <th>备注</th>
                  <!-- <th>关联车辆</th> -->
                </tr>
                <tr v-for="(item,index) in editTaskForm.testItems">
                  <td :style="{backgroundColor: item.inGroup?'#EDF2FC':''}">{{item.serialNumber}}</td>
                  <td :style="{backgroundColor: item.inGroup?'#EDF2FC':''}">{{item.itemName}}</td>
                  <td>{{item.itemPrice}}</td>
                  <td>{{item.sitePrice}}</td>
                  <td>
                    <el-input-number v-model="item.num" size="mini" style="width: 100px;" controls-position="right" :min="0" :max="10" label="" @change="computeTaskPrice()" :disabled="editForm.id==0?false:true"></el-input-number>
                  </td>
                  <td>
                    <el-input-number v-model="item.rebate" size="mini" style="width: 100px;" controls-position="right" :min="0" :max="100" label="" @change="computeTaskPrice()" :disabled="editForm.id==0?false:true"></el-input-number>
                  </td>
                  <td>{{item.price}}</td>
                  <td>
                    <el-input-number v-model="item.siteRebate" size="mini" style="width: 100px;" controls-position="right" :min="0" :max="100" label="" @change="computeTaskPrice()" :disabled="editForm.id==0?false:true"></el-input-number>
                  </td>
                  <td>{{item.priceSite}}</td>
                  <td>
                    <el-input-number v-model="item.costRebate" size="mini" style="width: 100px;" controls-position="right" :min="0" :max="100" label="" @change="computeTaskPrice()" :disabled="editForm.id==0?false:true"></el-input-number>
                  </td>
                  <td>{{item.priceCost}}</td>
                  <!-- <td>
                    <el-input-number v-model="item.costSiteRebate" size="mini" style="width: 100px;" controls-position="right" :min="0" :max="100" label="" @change="computeTaskPrice()"></el-input-number>
                  </td> -->
                  <td>{{item.priceSiteCost}}</td>
                  <td>
                    <el-input type="textarea" :rows="2" placeholder="" v-model="item.itemNote" size="mini" style="width: 150px;" controls-position="right"  :disabled="editForm.id==0?false:true"></el-input>
                  </td>
                  <!-- <td>
                    <el-select v-model="item.carIds" placeholder="请选择" size="mini"
                        :multiple="true"
                        :multiple-limit="item.num">
                      <el-option
                        v-for="item in carList"
                        :key="item.id"
                        :label="item.vin"
                        :value="item.id"></el-option>
                    </el-select>
                  </td> -->
                </tr>
              </table>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="检测费报价" label-width="100px">
              <el-input v-model="editTaskForm.priceItemPay" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="场地费报价" label-width="100px">
              <el-input v-model="editTaskForm.priceSitePay" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检测成本" label-width="100px">
              <el-input v-model="editTaskForm.priceItemCost" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="场地费成本" label-width="100px">
              <el-input v-model="editTaskForm.priceSiteCost" type="number" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showEditTaskDialog = false">关 闭</el-button>
        <!-- <el-button type="primary" @click.native.prevent="addOrderTask">确定</el-button> -->
      </div>
    </el-dialog>
    <!-- 添加检测项目 -->
    <el-dialog :visible.sync="showAddItemDialog" width="650px">
      <el-form :model="addItemForm" ref="addItemForm">
        <el-form-item label="检测项目" label-width="100px" prop="items">
          <el-cascader  style="width: 100%;"
              v-model="addItemForm.items"
              :options="addItems"
              :props="{ expandTrigger: 'click', value: 'id', label:'label', multiple: true }"
              ></el-cascader>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showAddItemDialog = false">关 闭</el-button>
        <el-button type="primary" @click.native.prevent="addToTaskItems">确定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {validPhone} from '@/common/utils/validate.js'
import request from '@/common/utils/request.js'
import util from '../../../common/utils/util.js'
import {getToken} from '../../../common/utils/auth.js'
import {getTestOrderAllList, saveOrNextTestOrder, deleteTestOrder, taskToUser, getOrderInfo, orderNext, updateOrderPrice,doneOrder,updateOrderSettlement,updateOrderPay,getTaskItemsCarAndLogsId} from "../../../api/test_order.js";
import {getAllTestCarEnterpriseList} from "../../../api/test_car_enterprise.js"
import {getTestCarListByEntId,getTestCarListByEntVin} from "../../../api/test_car.js"
import {getAllCarTypeList} from '../../../api/car_type.js'
import {getAllTestProductTypeList} from '../../../api/test_product_type.js'
import {getAllTestGroupListByParam,getTestGroupItemParam} from '../../../api/test_group.js'
import {getAllTestSiteList} from '../../../api/test_site.js'
import {getTestSitePrice, getTestSiteItemList} from '../../../api/test_site_price.js'
import {getAllUserList,getUser,getAllCarList,getUserRole} from '../../../api/user.js'
import {getAllTestOrgList} from '../../../api/test_org.js'
import {getTestItemList2, getTestItemListByGroupId} from '../../../api/test_item.js'
import {getAllTestoperationManagerList} from "@/api/test_operation_manager";
import axios from "axios";



export default {
  name: "testOrderManage3",
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      tableHeight: 200,
      editFormVisible:false,
      excleVisible:false,
      loading: false,
      suggestTime:'',
      productTypeId:'',
      doneFormVisible:false,
      userRole:0,
      doneForm:{
        doneTaskItemIds:[],
        next: 0,
        carId:'',
      },
      taskItems:[],
      excelImp: {
        dialogVisible: false,
        loading: false,
        fileList:[],
        action: '',
        loadingDiv:'',
        siteId:'',
      },
      editForm: {
        id: 0,
        tOrderId:0,
        carEnterpriseId:0,
        testTasks:[],
        priceCost: 0, // 成本总价
        price: 0, // 计算总价
        payPrice: 0, // 最终价
        payPriceStatus: 0, // 最终价是否修改过
        rebate: 100, // 车企默认折扣
        siteRebate: 100, // 车企场地默认折扣
        next: 0,
        brand:'',
        customerName:'',
        a: '',
        b: '',
        c: '',
        d: '',
        e: '',
        f: '',
        g: '',
        h: '',
        i: '',
        j: '',
        k: '',
        l: '',
        m: '',
        n: '',
        o: '',
        priceSiteCost : 0,//场地费成本
        priceSitePay : 0,//场地费报价
        priceItemCost : 0,//检测费成本
        priceItemPay : 0,//检测费报价
        amount : 0,//其他费用成本
        amountPay : 0,//其他费用报价
        interiorAmount : 0,//内部费用成本
        interiorAmountPay : 0,//内部费用报价



      },
      editRules: {
        carEnterpriseId: [{ required: true, message:"请选择车企", trigger: 'blur'}],
        customerName:[{ required: true, message:"请输入客户名称", trigger: 'blur'}],
      },
      loadingDiv: null,
      searchForm: {
        orderStatus: 0,
        carEnterpriseId:'',
        carTypeId:'',
        productTypeIds:'',
        customerName:'',
        closingPayPrice:'',
        closingCost:'',
      },
      carEntList:[],
      carList:[],
      carVinList:[],
      carTypeList:[],
      testProductTypeList: [],
      groupList: [],
      groupItemList:[],
      testSiteList:[],
      userList:[],
      orgList:[],
      hasDxDisabled:true,
      nextShow: false,
      customerNameList:[],

      showEditTaskDialog: false,
      editTaskIndex: -1,
      exportList:{
        serialNumber:'',
      },
      editTaskForm: {
        id: 0,
        tid:0,
        tOrderId: 0,
        carTypeId: '', // 车型
        carTypeName: '',
        productTypeId1: '', // 产品类别1级分类
        productTypeId2: '', // 产品类别2级分类
        productTypeName1: '',
        productTypeName2: '',
        siteId: '',
        orgId: '',
        groupId: '', // 套餐id
        groupName: '',
        groupPrice: '',
        groupItemIds: [],
        groupItemTIds: [],
        priceItemCost: 0,
        priceSiteCost: 0,
        priceItemPay: 0,
        priceSitePay: 0,
        payPriceCost:0,

        prDate:'',
        name:'',
        model:'',
        vin:'',
        color:'',
        sendSample: 0,
        suggestTime:'',
        importance: 0,
        cause:'',
        carId: 0,



        note: '',
        testItems:[],
        productTypeIds:[],

        msg :'',
        currentStep:'',
        currentStepUserId:'',
        historyStep:'',
        historyStepUserId:'',
        rollbackStep:'',

        sendSampleTime:'',
        carPeopleNote:'',
        carPeople:'',


        //公告：ABCDEFGHIK 1
        //达标：ABCDEFGHJKLMN 2
        //CCC：ABCDEFKG 3
        //环保：ABCDEFK 4
        //其他：ABCDEFKO 19
      },
      editTaskRules: {
        carTypeId: [{ required: true, message:"请选择车企", trigger: 'blur'}],
        productTypeIds: [{ required: true, message:"请选择产品类型", trigger: 'blur'}],
        siteId: [{ required: true, message:"请选择检测场地", trigger: 'blur'}],
        orgId: [{ required: true, message:"请选择检测机构", trigger: 'blur'}],
        testItems: [{ required: true, message:"请添加检测项目", trigger: 'blur'}],

      },

      showAddItemDialog: false,
      addItemForm:{
        items:[]
      },
      addItems:[],

      siteItemList: [],
    }
  },
  watch:{
    $route (to, from ) {
      // 监听路由变化, 实现类似 小程序的 onShow 事件
      if (to.path === '/task/test_order_manage/0') {
        if(this.nextShow){
          this.editFormVisible = true;
          this.nextShow = false;
        }
      }
    }

  },
  computed:{
    carEntDisabled(){
      if(this.editForm.testTasks && this.editForm.testTasks.length > 0){
        return true;
      }
      return false;
    },
    carEntDisableds(){
      if(util.isEmpty(this.editTaskForm.carId)){
        return false;
      }
      return true;
    },
    userListAB(){
      if(util.isEmpty(this.userList)){
        return [];
      }

      let arr = [];
      arr.push({id:0, nickname:'不适用'});
      for(let i in this.userList){
        if(this.userList[i].id == this.editForm.c){
          continue;
        }
        arr.push(this.userList[i]);
      }

      return arr;
    },
    userListC(){
      if(util.isEmpty(this.userList)){
        return [];
      }

      let arr = [];
      for(let i in this.userList){
        if(this.userList[i].id == this.editForm.a || this.userList[i].id == this.editForm.b){
          continue;
        }
        arr.push(this.userList[i]);
      }

      return arr;
    },

    userListD(){
      if(util.isEmpty(this.userList)){
        return [];
      }

      let arr = [];
      for(let i in this.userList){
        if(this.userList[i].id == this.editForm.e){
          continue;
        }
        arr.push(this.userList[i]);
      }

      return arr;
    },

    userListE(){
      if(util.isEmpty(this.userList)){
        return [];
      }

      let arr = [];
      for(let i in this.userList){
        if(this.userList[i].id == this.editForm.d){
          continue;
        }
        arr.push(this.userList[i]);
      }

      return arr;
    },
  },
  created() {
    let step=this.$route.params.step;
    if(step == 0){
      this.searchForm.orderStatus=0;
    }else if(step == 1){
      this.searchForm.orderStatus=1;
    }else if(step == 2){
      this.searchForm.orderStatus=2;
    }
  },
  mounted() {
    this.init();
    this.getDataList(this.currentPage);

    this.$nextTick(() => {
        this.tableHeight = document.documentElement.clientHeight - 198;
    })
    window.onresize = () => {
      this.$nextTick(() => {
          this.tableHeight = document.documentElement.clientHeight - 198;
      })
    }

    let t = getToken();
    this.fileBaseUrl = this.$adminApiUrl+"/file/get?_t="+t+"&f=";


    this.excelImp.action = this.$adminApiUrl + "test-order/excel?userType=0&_t="+t+"&orderStatus="+this.$route.params.step;
    this.baseUrl = this.$baseUrl;
    this.uploadActionUrl = this.$adminApiUrl + "/uploadToQiNiu?_t="+t;
  },
  methods: {

    settlement(){
      // console.log(this.multipleSelection.length)
      if(this.multipleSelection==""||this.multipleSelection==null){
        this.$alert("请选择任务单", {dangerouslyUseHTMLString:true,type:'warning'})
        return ""
      }
      var id=[];
      console.log(this.multipleSelection)
      for(var i=0;i<this.multipleSelection.length;i++){
        id.push(this.multipleSelection[i].id)
      }
      // console.log(id)
      this.idList = id;
      // console.log(this.idList)
          updateOrderSettlement({idList:this.idList}).then(res => {
          if(res.code == 0) {
            this.$alert(res.msg, "保存失败", {dangerouslyUseHTMLString:true,type:'warning'})
          }else if(res.code == 1) {
            this.$alert(res.msg, "保存成功", {dangerouslyUseHTMLString:true,type:'success'})
              .then(()=> {
                this.editFormVisible=false;
                this.getDataList(this.currentPage)
              })
          }

        })
    },
    pay(){
      let id=[];
      if(this.multipleSelection==""||this.multipleSelection==null){
        this.$alert("请选择任务单", {dangerouslyUseHTMLString:true,type:'warning'})
        return ""
      }
      for(var i=0;i<this.multipleSelection.length;i++){
        id.push(this.multipleSelection[i].id)
      }
      this.idList = id;
          updateOrderPay({idList:this.idList}).then(res => {
          if(res.code == 0) {
            this.$alert(res.msg, "保存失败", {dangerouslyUseHTMLString:true,type:'warning'})
          }else if(res.code == 1) {
            this.$alert(res.msg, "保存成功", {dangerouslyUseHTMLString:true,type:'success'})
              .then(()=> {
                this.editFormVisible=false;
                this.getDataList(this.currentPage)
              })
          }

        })
    },


    exportExcel(){
      if(this.multipleSelection==""||this.multipleSelection==null){
        const loadingDiv = util.showLoading("正在导出EXCEL")

        let param = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
          orderStatus: this.searchForm.orderStatus,
          carEnterpriseId: this.searchForm.carEnterpriseId,
          carTypeId: this.searchForm.carTypeId,
          productTypeIds: this.searchForm.productTypeIds,
          customerName: this.searchForm.customerName,
          closingPayPrice: this.searchForm.closingPayPrice,
          closingCost: this.searchForm.closingCost,
        };

        // param['siteId'] = this.$route.params.id;
        // console.log(param);

        let t = getToken();
        let headers = {"x-token": t};
        axios({
          method: 'post',
          url: this.$adminApiUrl + "test-order/all-excel-export", // 请求地址

          data: param, // 参数
          headers: headers,
          responseType: 'blob' ,// 表明返回服务器返回的数据类型

        }).then(res=>{
          loadingDiv.close();
          let blob = new Blob([res.data], { type: 'application/xlsx' })
          let url = window.URL.createObjectURL(blob)
          const link = document.createElement('a') // 创建a标签
          link.href = url;
          let timeStr = "";//this.fmtDate(new Date(),"yyyyMMdd_hhmmss");
          link.download = '全部任务'+ '.xlsx' // 重命名文件
          link.click()
          URL.revokeObjectURL(url)

        }).catch(err=>{
          // console.log(err);
          loadingDiv.close();
          this.$alert("导出失败,请检查网络", {dangerouslyUseHTMLString:true,type:'warning'})
        });
      }else{
        const loadingDiv = util.showLoading("正在导出EXCEL")
        this.exportList = this.multipleSelection;

        // console.log(this.multipleSelection.length)
        for(var k=0;k<this.multipleSelection.length;k++){
          // console.log("123")

          if(!util.isEmpty(this.multipleSelection[k].serialNumber)&&!util.isEmpty(this.multipleSelection[k].itemNum)){
            let arrTemp = this.multipleSelection[k].serialNumber.split(",");
            let arr= this.multipleSelection[k].itemNum.split(",");
            let sArr = [];
            for(let i in arrTemp){
                let num = parseInt(arr[i]);
                // console.log(num)
                for(let j=0;j<num;j++){
                  sArr.push(arrTemp[i]);
                }
            }

            var arrs = sArr;
            var res = []; //
            // arrs.sort();
            for (var i = 0; i < arrs.length;) {
                var count = 0;
                for (var j = i; j < arrs.length; j++) {
                    if (arrs[i] == arrs[j]) {
                        count++;
                    }
                }
                res.push([arrs[i], count]);
                i += count;
            }
            //_res 二维数维中保存了 值和值的重复数
            var newArr = [];
            for (var i = 0; i < res.length; i++) {
                // console.log(res[i][0] + "重复次数:" + res[i][1]);
                newArr.push(res[i][0] + '*' + res[i][1]);
            }
            // console.log(arrTemps);
            // console.log(newArr.join(","));

            var serialNumber = newArr.join(",");
            this.exportList[k].serialNumber = serialNumber;
          }else{
            this.exportList[k].serialNumber = this.multipleSelection[k].itemList;
          }



          var orderStatus = '';
          if (this.multipleSelection[k].orderStatus==0){
            orderStatus =  "未开始";
            }else if(this.multipleSelection[k].orderStatus==1){
              orderStatus =  "已完成";
            }else{
              orderStatus =  "进行中";
            }
          this.multipleSelection[k].orderStatus = orderStatus;
          this.multipleSelection[k].priceCost = this.multipleSelection[k].priceCost+this.multipleSelection[k].amount+this.multipleSelection[k].interiorAmount;

          if(this.multipleSelection[k].payPriceCost==null||this.multipleSelection[k].payPriceCost==0){
            this.multipleSelection[k].payPriceCost = this.multipleSelection[k].priceCost;
          }
          if (this.multipleSelection[k].closingCost==0){
             this.multipleSelection[k].closingCost = "未支付";
            }else{
               this.multipleSelection[k].closingCost = "已支付";
            }

          this.multipleSelection[k].price = this.multipleSelection[k].price+this.multipleSelection[k].amountPay+this.multipleSelection[k].interiorAmountPay;

          if (this.multipleSelection[k].closingPayPrice==0){
            this.multipleSelection[k].closingPayPrice = "未结算";
            }else{
              this.multipleSelection[k].closingPayPrice = "已结算";
            }

            if(!util.isEmpty(this.multipleSelection[k].productTypeId)){
            let arrTemps = this.multipleSelection[k].productTypeId.split(",");
            let m = 0;
            arrTemps = arrTemps.map(Number);

            for(var i=0;i<arrTemps.length;i++){
              if(arrTemps[i]==2){
                m = m+1
              }
            }

            this.multipleSelection[k].nums = this.multipleSelection[k].nums-m;
            }else{
              this.multipleSelection[k].nums = this.multipleSelection[k].numList;
            }







          // exportList.push("id",this.multipleSelection[i].id)

        }

        let param = {
          exportList:this.exportList
        };

        let t = getToken();
        let headers = {"x-token": t};
        axios({
          method: 'post',
          url: this.$adminApiUrl + "/test-order/all-excel-export-list", // 请求地址

          data: param, // 参数
          headers: headers,
          responseType: 'blob' ,// 表明返回服务器返回的数据类型

        }).then(res=>{
          loadingDiv.close();
          let blob = new Blob([res.data], { type: 'application/xlsx' })
          let url = window.URL.createObjectURL(blob)
          const link = document.createElement('a') // 创建a标签
          link.href = url;
          let timeStr = "";//this.fmtDate(new Date(),"yyyyMMdd_hhmmss");
          link.download = '全部任务'+ '.xlsx' // 重命名文件
          link.click()
          URL.revokeObjectURL(url)

        }).catch(err=>{
          // console.log(err);
          loadingDiv.close();
          this.$alert("导出失败,请检查网络", {dangerouslyUseHTMLString:true,type:'warning'})

        });
      }
      this.getDataList(this.currentPage)
    },





    handleExcelImp(){

      this.excelImp.fileList=[];
      this.excelImp.dialogVisible = true;
    },
    onUploadSuccess(res, file, fileList){
      this.excelImp.loading = false;
      this.excelImp.loadingDiv.close();

      if(res.code == 0) {
        this.$alert(res.msg,{dangerouslyUseHTMLString:true,type:'warning'})
      }else if(res.code == 1) {
        this.$alert(res.msg,{dangerouslyUseHTMLString:true,type:'success'})
          .then(()=> {
            this.getDataList(this.currentPage);
            this.excelImp.dialogVisible=false;
          })
      }
    },
    onUploadError(err, file, fileList){
      this.excelImp.loading = false;
      this.excelImp.loadingDiv.close();
      this.$alert("导入失败",{dangerouslyUseHTMLString:true,type:'warning'})
    },
    submitUpload() {
      this.excelImp.loading = true;
      this.excelImp.loadingDiv = util.showLoading("导入中")
      this.$refs.upload.submit();
    },
    GroupChange(){
      // console.log(this.editTaskForm.priceItemPay)


    },

    onGroupChange(){
      if(util.isEmpty(this.editTaskForm.groupId)){
        this.editTaskForm.groupItemIds = [];
        this.editTaskForm.groupItemTIds = [];
        this.editTaskForm.groupId = '';
        this.editTaskForm.groupName = '';
        this.editTaskForm.groupPrice = '';
        return;
      }

      let testGroup;
      for(let i in this.groupList){
        if(this.groupList[i].id == this.editTaskForm.groupId){
          testGroup = this.groupList[i];
          break;
        }
      }

      this.editTaskForm.groupItemTIds=[];

      if(util.isNotEmpty(testGroup.itemTIds)){
        let arr = [];
        let arrStr = testGroup.itemTIds.split(",");
        for(let i in arrStr){
          if(!util.isEmpty(arrStr[i])){
            arr.push(parseInt(arrStr[i]))
          }
        }

        this.editTaskForm.groupItemTIds = arr;
        this.editTaskForm.groupId = testGroup.id;
        this.editTaskForm.groupName = testGroup.name;
        this.editTaskForm.groupPrice = testGroup.price;
        this.addItemForm.items = arr;

      }

      this.loadTestItems(()=>{
        this.taskItemsMerge();
      });
    },
    carVin(){
      for(var i=0;i<this.carVinList.length;i++){
        if(this.carVinList[i].id==this.editTaskForm.carId){
          this.editTaskForm.color = this.carVinList[i].color
          this.editTaskForm.name = this.carVinList[i].name
          this.editTaskForm.model = this.carVinList[i].model
          this.editTaskForm.vin = this.carVinList[i].vin
          this.editTaskForm.prDate = this.carVinList[i].prDate
        }

      }
    },
    onProductTypeChange(){
      this.groupList = [];
      this.editTaskForm.groupId = '';
      this.editTaskForm.testItems = [];
      this.editTaskForm.productTypeId1 = this.editTaskForm.productTypeIds[0];
      this.editTaskForm.productTypeId2 = this.editTaskForm.productTypeIds[1];
      if(this.editForm.productTypeIds!=null&&this.editForm.productTypeIds!=''){
        this.editForm.productTypeId1 = this.editForm.productTypeIds[0];
        this.editForm.productTypeId2 = this.editForm.productTypeIds[1];
      }


      for(let i in this.testProductTypeList){
        if(this.testProductTypeList[i].id == this.editTaskForm.productTypeId1){
          this.editTaskForm.productTypeName1 = this.testProductTypeList[i].name;
          let list = this.testProductTypeList[i].children;
          for(let j in list){
            if(list[j].id == this.editTaskForm.productTypeId2){
              this.editTaskForm.productTypeName2 = list[j].name;
              break;
            }
          }
          break;
        }
      }


      this.getGroupList();
    },
    onPayPriceChange(){
      if(this.editForm.price != this.editForm.payPrice){
        this.editForm.payPriceStatus = 1;
      }
    },

    onPayPriceCost(){
      if(this.editForm.price != this.editForm.payPrice){
        this.editForm.payPriceStatus = 1;
      }
    },
    showAddOrderTask(){
      this.loadCarList();

      if(util.isEmpty(this.editForm.carEnterpriseId)){
        this.$message({
          showClose: true,
          message: "请选择车企",
          type: 'error'
        });
        return;
      }

      for(let key in this.editTaskForm){
        this.editTaskForm[key] = '';
      }

      this.editTaskForm.id=0;
      this.editTaskForm.testItems = [];
      this.editTaskForm.productTypeIds=[];
      this.editTaskForm.groupItemTIds=[];
      this.editTaskIndex = -1;


      this.showEditTaskDialog = true;
    },
    loadCarList(){
      getTestCarListByEntId({carEnterpriseId: this.editForm.carEnterpriseId}).then(res=>{
        if(res.code == 1){
          this.carList = res.data;
        }
      });
      getTestCarListByEntVin({carEnterpriseId: this.editForm.carEnterpriseId,name:this.editForm.name,model:this.editForm.model}).then(res=>{
        if(res.code == 1){
          this.carVinList = res.data;
          // console.log("123")
          // console.log(this.carVinList)
        }
      });
    },
    onCarTypeChange(){
      this.groupList = [];
      this.editTaskForm.groupId = '';
      this.editTaskForm.testItems = [];
      for(let i in this.carTypeList){
        if(this.carTypeList[i].id == this.editTaskForm.carTypeId){
          this.editTaskForm.carTypeName = this.carTypeList[i].name;
          break;
        }
      }
      this.getGroupList();
    },
    getGroupList(){
      if(util.isEmpty(this.editTaskForm.productTypeId1)
      || util.isEmpty(this.editTaskForm.productTypeId2)
      || util.isEmpty(this.editTaskForm.carTypeId)){
        this.groupList = [];
        return;
      }

      let param = {
        carTypeId: this.editTaskForm.carTypeId,
        productTypeId1: this.editTaskForm.productTypeId1,
        productTypeId2: this.editTaskForm.productTypeId2,
      }

      getAllTestGroupListByParam(param).then(res=>{
        if(res.code == 1){
          this.groupList = res.data;
        }
      });
    },
    onUserHChange(e){
      switch(this.editForm.productTypeId1){
        case 1: // 公告
          this.editForm.i = e;
          this.editForm.k = e;
          break;
        case 2: // 达标车型
          this.editForm.j = e;
          this.editForm.k = e;
          this.editForm.l = e;
          this.editForm.m = e;
          this.editForm.n = e;
          break;
      }
    },
    computeTaskPrice(){
      if(util.isEmpty(this.editTaskForm.testItems)){
        this.editTaskForm.priceItemCost = 0;
        this.editTaskForm.priceSiteCost = 0;
        this.editTaskForm.priceItemPay = 0;
        this.editTaskForm.priceSitePay = 0;
      }

      // 获取场地费
      this.siteItemList = [];
      if(util.isEmpty(this.editTaskForm.siteId)){
        this.execComputeTaskPrice();
      }else{
        getTestSiteItemList({siteId: this.editTaskForm.siteId}).then(res=>{
          // console.log(res)
          if(res.code == 1){
            this.siteItemList = res.data;
            for(let i in this.editTaskForm.testItems){
              let item = this.editTaskForm.testItems[i];
              item.sitePrice = this.getSiteItemPrice(item.itemTId);
            }
            this.execComputeTaskPrice();
          }else{
            this.$message({
              showClose: true,
              message: "获取场地费失败,价格计算失败1.",
              type: 'error'
            });
          }
        }).catch(err=>{
          console.error(err)
          this.$message({
            showClose: true,
            message: "获取场地费失败,价格计算失败2.",
            type: 'error'
          });
        })
      }
    },
    showChoseItemDialog(){
      if(util.isEmpty(this.editTaskForm.carTypeId)){
        this.$message({
          showClose: true,
          message: "请先选择车型",
          type: 'error'
        });
        return;
      }
      if(util.isEmpty(this.editTaskForm.productTypeId1)
        || util.isEmpty(this.editTaskForm.productTypeId2)){
        this.$message({
          showClose: true,
          message: "请先选择产品类型",
          type: 'error'
        });
        return;
      }

      this.addItemForm.items=[];
      this.loadTestItems();


      this.showAddItemDialog = true;

    },
    loadTestItems(fn){
      this.addItems = [];

      const loadingDiv = util.showLoading("加载中...")
      const param = {
        carTypeId: this.editTaskForm.carTypeId,
        productTypeId1: this.editTaskForm.productTypeId1,
        productTypeId2: this.editTaskForm.productTypeId2,
      }

      getTestItemList2(param).then(res=>{
        loadingDiv.close();
        if(res.code == 1){
          //this.addItems = res.data;
          let arr = [];
          let data = res.data;

          for(let i in data){
            let item = data[i];
            item['label'] = item.serialNumber + "-" + item.itemName;
            arr.push(item)
          }

          this.addItems = arr;

          if(fn){
            fn();
          }
        }else{
          this.$message({
            showClose: true,
            message: "加载检测项目失败",
            type: 'error'
          });
        }
      }).catch(err=>{
        console.error(err)
        loadingDiv.close();
      });
    },
    addToTaskItems(){
      if(this.addItemForm.items && this.addItemForm.items.length > 0 ){
        this.taskItemsMerge();
      }

      this.showAddItemDialog = false;
    },
    getItem(itemId){
      for(let i in this.addItems){
        if(itemId == this.addItems[i].tId || itemId == this.addItems[i].id){
          return this.addItems[i];
        }
      }
    },
    taskItemsMerge(){
      const testItems = this.editTaskForm.testItems;
      for(let i in this.addItemForm.items){
        let addItem = this.getItem(this.addItemForm.items[i]);
        if(util.isEmpty(addItem)){
          continue;
        }
        let inFlag = false;
        for(let j in testItems){
          if(addItem.tId == testItems[j].itemTId){
            inFlag = true;
            break;
          }
        }

        if(addItem && !inFlag){
          let ii = {
            id: 0,
            itemId: addItem.id,
            itemTId: addItem.tId,
            itemName: addItem.itemName,
            serialNumber: addItem.serialNumber,
            itemPrice: addItem.price,
            sitePrice: 0, // 场地费
            num: 1,
            rebate: this.editForm.rebate,
            price: 0,
            siteRebate: this.editForm.siteRebate,
            priceSite:0,
            costRebate: 100,
            priceCost: 0,
            costSiteRebate: 100,
            priceSiteCost: 0,
            carIds:[],
            inGroup: 0,
          }

          testItems.push(ii);
        }
      }
      this.resetInGroup()
    },
    resetInGroup(){
      let groupItemIds = [];
      for(let i in this.editTaskForm.testItems){
        let item = this.editTaskForm.testItems[i];
        if((!util.isEmpty(this.editTaskForm.groupItemTIds))
          && this.editTaskForm.groupItemTIds.indexOf(item.itemTId) != -1
        ){
          item.inGroup = 1;
          groupItemIds.push(item.itemId);
        }else{
          item.inGroup = 0;
        }
      }

      if(!util.isEmpty(groupItemIds)){
        this.editTaskForm.groupItemIds = groupItemIds.join();
      }

      this.computeTaskPrice()

    },
    addOrderTask(){
      if(util.isEmpty(this.editTaskForm.carTypeId)){
        this.$message.error('请选择车型');
        return;
      }
      if(util.isEmpty(this.editTaskForm.productTypeId1) || util.isEmpty(this.editTaskForm.productTypeId2)){
        this.$message.error('请选择产品类型');
        return;
      }
      if(util.isEmpty(this.editTaskForm.testItems)){
        this.$message.error('请选择检测项目');
        return;
      }

      if(this.editTaskForm.carPeople==null||this.editTaskForm.carPeople==''){
        this.editTaskForm.carPeople = [];

      }

      //公告：ABCDEFGHIK 1
      //达标：ABCDEFGHJKLMN 2
      //CCC：ABCDEFKG 3
      //环保：ABCDEFK 4
      //其他：ABCDEFKO 19
      // switch(this.editTaskForm.productTypeId1){
      //   case 1:
      //     if(util.isEmpty(this.editTaskForm.a)
      //       || util.isEmpty(this.editTaskForm.b)
      //       || util.isEmpty(this.editTaskForm.c)
      //       || util.isEmpty(this.editTaskForm.d)
      //       || util.isEmpty(this.editTaskForm.e)
      //       || util.isEmpty(this.editTaskForm.f)
      //       || util.isEmpty(this.editTaskForm.g)
      //       || util.isEmpty(this.editTaskForm.h)
      //       || util.isEmpty(this.editTaskForm.i)
      //       || util.isEmpty(this.editTaskForm.k)){
      //       this.$message.error('请选择检测工程师');
      //       return;
      //     }
      //     break;
      //   case 2:
      //     if(util.isEmpty(this.editTaskForm.a)
      //       || util.isEmpty(this.editTaskForm.b)
      //       || util.isEmpty(this.editTaskForm.c)
      //       || util.isEmpty(this.editTaskForm.d)
      //       || util.isEmpty(this.editTaskForm.e)
      //       || util.isEmpty(this.editTaskForm.f)
      //       || util.isEmpty(this.editTaskForm.g)
      //       || util.isEmpty(this.editTaskForm.h)
      //       || util.isEmpty(this.editTaskForm.j)
      //       || util.isEmpty(this.editTaskForm.k)
      //       || util.isEmpty(this.editTaskForm.l)
      //       || util.isEmpty(this.editTaskForm.m)
      //       || util.isEmpty(this.editTaskForm.n)){
      //       this.$message.error('请选择检测工程师');
      //       return;
      //     }
      //     break;
      //   case 3:

      //     if(util.isEmpty(this.editTaskForm.a)
      //       || util.isEmpty(this.editTaskForm.b)
      //       || util.isEmpty(this.editTaskForm.c)
      //       || util.isEmpty(this.editTaskForm.d)
      //       || util.isEmpty(this.editTaskForm.e)
      //       || util.isEmpty(this.editTaskForm.f)
      //       || util.isEmpty(this.editTaskForm.k)
      //       || util.isEmpty(this.editTaskForm.g)){
      //       this.$message.error('请选择检测工程师');
      //       return;
      //     }
      //     break;
      //   case 4:

      //     if(util.isEmpty(this.editTaskForm.a)
      //       || util.isEmpty(this.editTaskForm.b)
      //       || util.isEmpty(this.editTaskForm.c)
      //       || util.isEmpty(this.editTaskForm.d)
      //       || util.isEmpty(this.editTaskForm.e)
      //       || util.isEmpty(this.editTaskForm.f)
      //       || util.isEmpty(this.editTaskForm.k)){
      //       this.$message.error('请选择检测工程师');
      //       return;
      //     }
      //     break;
      //   case 19:
      //     if(util.isEmpty(this.editTaskForm.a)
      //       || util.isEmpty(this.editTaskForm.b)
      //       || util.isEmpty(this.editTaskForm.c)
      //       || util.isEmpty(this.editTaskForm.d)
      //       || util.isEmpty(this.editTaskForm.e)
      //       || util.isEmpty(this.editTaskForm.f)
      //       || util.isEmpty(this.editTaskForm.k)
      //       || util.isEmpty(this.editTaskForm.o)){
      //       this.$message.error('请选择检测工程师');
      //       return;
      //     }
      //     break;
      // }


      if(this.editTaskIndex == -1){
        this.editForm.testTasks.push(JSON.parse(JSON.stringify(this.editTaskForm)))
      }else{
        this.editForm.testTasks[this.editTaskIndex] = JSON.parse(JSON.stringify(this.editTaskForm));
      }
      this.computeOrderPrice()

      this.showEditTaskDialog = false;
    },
    onTaskEditClick(index){
      this.editTaskIndex = index;
      this.editTaskForm = JSON.parse(JSON.stringify(this.editForm.testTasks[index]));

      this.editTaskForm.productTypeIds=[this.editTaskForm.productTypeId1, this.editTaskForm.productTypeId2];
      this.getGroupList();
      this.loadCarList();
      this.showEditTaskDialog = true;
    },
    removeOrderTask(index){
      this.editForm.testTasks.splice(index, 1);
      this.computeOrderPrice();
    },
    execComputeTaskPrice(){
      // 计算价格
      let priceItemCost = 0;
      let priceSiteCost = 0;
      let priceItemPay = 0;
      let priceSitePay = 0;

      let items = this.editTaskForm.testItems;

      for(let i in items){
        let item = items[i];
        let num = 0;
        let numCost = (item.num>=1)?(item.num):0;
        if(item.inGroup){
          num = (item.num>1)?(item.num-1):0;
        }else{
          num = (item.num>=1)?(item.num):0;
        }

        item.price = Math.round(item.itemPrice * num * item.rebate / 100); // 价格
        item.priceCost = Math.round(item.itemPrice * numCost * item.costRebate / 100); // 成本
        item.priceSite = Math.round(item.sitePrice * numCost * item.siteRebate / 100); // 场地费
        item.priceSiteCost = Math.round(item.sitePrice * numCost * item.costSiteRebate / 100); // 场地费成本

        priceItemPay += item.price;
        priceItemCost += item.priceCost;
        priceSitePay += item.priceSite;
        priceSiteCost += item.priceSiteCost;
      }

      // 单项价格 + 套餐价
      if(!util.isEmpty(this.editTaskForm.groupPrice)){
        priceItemPay += this.editTaskForm.groupPrice;
      }

      this.editTaskForm.priceItemCost = priceItemCost;
      this.editTaskForm.priceSiteCost = priceSiteCost;
      this.editTaskForm.priceItemPay = priceItemPay;
      this.editTaskForm.priceSitePay = priceSitePay;
    },
    computeOrderPrice(){
      if(util.isEmpty(this.editForm.testTasks)){
        this.editForm.price = 0;
        this.editForm.payPrice = 0;
        this.editForm.payPriceStatus = 0;
        this.editForm.priceCost = 0;
        return ;
      }

      let price = 0;
      let priceCost = 0;
      for(let i in this.editForm.testTasks){
        price += this.editForm.testTasks[i].priceItemPay + this.editForm.testTasks[i].priceSitePay;
        priceCost += this.editForm.testTasks[i].priceItemCost + this.editForm.testTasks[i].priceSiteCost;
      }

      this.editForm.price = price;
      this.editForm.priceCost = priceCost;
      if(this.editForm.payPriceStatus == 0){
        this.editForm.payPrice = price;
      }


    },
    getSiteItemPrice(itemTId){
      if(util.isEmpty(this.siteItemList)){
        return 0;
      }

      for(let i in this.siteItemList){
        if(this.siteItemList[i].itemTId == itemTId){
          return this.siteItemList[i].price;
        }
      }

      return 0;

    },





  handleSelectionChange(val) {
    this.multipleSelection = val;
  },



    handleShowTask(index, row){
      let item = {
        componentName:"taskManage",
        icon:"",
        path:"/task/task_manage/"+row.tOrderId+"/"+row.carEnterpriseId,
        title: "查看任务",
      };

      this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}})
    },
    handleOrderDone(index, row){
      const loadingDiv = util.showLoading("任务单完成中")
      this.loading = true;
      doneOrder({tOrderId: row.tOrderId}).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              this.editFormVisible=false;
              this.getDataList(this.currentPage)
            })
        }
        this.loading = false;
        loadingDiv.close();
      }).catch(res => {
        this.loading = false;
        loadingDiv.close();
      })
    },

    handleOrderEditExcel(index, row){
      // console.log("修改");
      getOrderInfo({id: row.id}).then(res=>{
        // console.log(res.data);
        this.editForm = res.data;
        if(!util.isEmpty(this.editForm.testTasks)){
          for(let i in this.editForm.testTasks){
            let tasks = this.editForm.testTasks[i];
            if(!util.isEmpty(tasks.carPeople)){
               tasks.carPeople = tasks.carPeople.split(",").map(Number);
               }else {
                 tasks.carPeople = [];
               }
            if(!util.isEmpty(tasks.groupItemTIds)){
              let arrStr = tasks.groupItemTIds.split(",")
              let arr = [];

              for(let i in arrStr){
                if(!util.isEmpty(arrStr[i])){
                  arr.push(parseInt(arrStr[i]));
                }
              }

              tasks.groupItemTIds = arr;
            }else{
              tasks.groupItemTIds = [];
            }
          }
        }


        this.excleVisible = true;
        this.editForm.priceCost = this.editForm.priceCost+row.amount+row.interiorAmount;
        this.editForm.price = this.editForm.price+row.amountPay+row.interiorAmountPay;
        this.editForm.amount = row.amount;
        this.editForm.amountPay = row.amountPay;
        this.editForm.interiorAmount = row.interiorAmount;
        this.editForm.interiorAmountPay = row.interiorAmountPay;
        
        // console.log( this.editForm.payPriceCost)
        if(row.payPriceCost==null||row.payPriceCost==0){
          this.editForm.payPriceCost =  this.editForm.priceCost;
        }



      })
    },





    handleOrderEdit(index, row){
      // console.log("修改");
      getOrderInfo({id: row.id}).then(res=>{
        // console.log(res.data);
        this.editForm = res.data;

        if(!util.isEmpty(this.editForm.testTasks)){
          for(let i in this.editForm.testTasks){
            let tasks = this.editForm.testTasks[i];
            if(!util.isEmpty(tasks.carPeople)){
               tasks.carPeople = tasks.carPeople.split(",").map(Number);
               }else {
                 tasks.carPeople = [];
               }
            if(!util.isEmpty(tasks.groupItemTIds)){
              let arrStr = tasks.groupItemTIds.split(",")
              let arr = [];

              for(let i in arrStr){
                if(!util.isEmpty(arrStr[i])){
                  arr.push(parseInt(arrStr[i]));
                }
              }

              tasks.groupItemTIds = arr;
            }else{
              tasks.groupItemTIds = [];
            }
          }
        }
        this.editForm.productTypeName1 = this.editForm.testTasks[0].productTypeName1;
        this.editForm.productTypeName2 = this.editForm.testTasks[0].productTypeName2;
        this.editForm.productTypeId1 = this.editForm.testTasks[0].productTypeId1;
        this.editForm.productTypeId2 = this.editForm.testTasks[0].productTypeId2;
        this.editForm.productTypeIds=[this.editForm.productTypeId1, this.editForm.productTypeId2];
        this.editForm.suggestTime = this.editForm.testTasks[0].suggestTime;
        this.editForm.importance = this.editForm.testTasks[0].importance;
        this.editForm.cause = this.editForm.testTasks[0].cause;
        this.editForm.name=this.editForm.testTasks[0].name;
        this.editForm.model=this.editForm.testTasks[0].model;
        // console.log("123")
        // console.log(this.editForm.testTasks[0].productTypeName1)


        this.editForm.amount = row.amount;
        this.editForm.amountPay = row.amountPay;
        this.editForm.interiorAmount = row.interiorAmount;
        this.editForm.interiorAmountPay = row.interiorAmountPay;
        this.editFormVisible = true;
        // console.log( this.editForm.priceCost)
        this.editForm.priceCost = this.editForm.priceCost+row.amount+row.interiorAmount;
        this.editForm.price = this.editForm.price+row.amountPay+row.interiorAmountPay;
        // console.log( this.editForm.payPriceCost)
        if(row.payPriceCost==null||row.payPriceCost==0){
          this.editForm.payPriceCost =  this.editForm.priceCost;
        }

        // console.log( this.editForm.payPriceCost)
        // console.log(row.amount)


      })
    },
    init(){
      getAllTestCarEnterpriseList().then(res => {
        if(res.code == 1) {
          this.carEntList = res.data;
        }
      }).catch(res => {

      })
      this.getAllCarTypeList();

      // 获取所有检测产品类别
      getAllTestProductTypeList().then(res => {
        if(res.code == 1) {
          this.testProductTypeList = res.data;
        }
      }).catch(res => {

      });

      // 获取所有检测场地
      getAllTestSiteList().then(res => {
        if(res.code == 1) {
          this.testSiteList = res.data;
        }
      }).catch(res => {

      });
      // 获取所有业务经理
      getAllTestoperationManagerList().then(res => {
        if(res.code == 1) {
          this.customerNameList = res.data;
        }
      }).catch(res => {

      });

      // 获取所有用户列表
      getAllUserList().then(res => {
        if(res.code == 1) {
          this.userList = res.data;
        }
      }).catch(res => {

      });

      getAllTestOrgList().then(res => {
        if(res.code == 1) {
          this.orgList = res.data;
        }
      }).catch(res => {

      });

    },
    getAllCarTypeList(){
      getAllCarTypeList().then(res=>{
        if(res.code == 1) {
          this.carTypeList = res.data;
        }
      }).catch(res => {

      })
    },
    refreshCarEntList(){
      getAllTestCarEnterpriseList().then(res => {
        if(res.code == 1) {
          this.carEntList = res.data;
          this.$message({
            showClose: true,
            message: "刷新成功",
            type: 'success'
          });
        }
      }).catch(res => {

      })
    },
    handlerOpenPage(t){

      let item = {};

      switch(t){
        case 1: // 跳转到车型管理
          item = {
            componentName:"testCarEnterpriseManage",
            icon:"",
            path:"/base/test_car_enterprise_manage",
            title: "车型类别管理",
          };
          break;
        case 2: // 跳转到车辆管理
          item = {
            componentName:"testCarManage",
            icon:"",
            path:"/test_car/test_car_manage",
            title: "车辆管理",
          };
          break;
      }

      this.editFormVisible=false;
      this.nextShow = true;
      this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}});

      // window.open("/#/base/car_type_manage");
    },


    fmtDate(d2, fmt) { // yyyy-MM-dd hh:mm:ss
      if (util.isEmpty(d2) || d2 <= 0){
        return "";
      }
      return  util.fmtDate(new Date(d2), fmt);
    },

    nameModel(name,model){
      if(name==null||model==null||name==''||model==''){
        return "";
      }else{
        return  name+'('+model+')'
      }
    },

    serialNumber(data,data1,itemList){
      if(util.isEmpty(data)){
        return itemList;
      }
      if(!util.isEmpty(data)&&!util.isEmpty(data1)){
        let arr= data1.split(",");
        let arrTemps = data.split(",");


        let arrTemp = data.split(",");

        let sArr = [];
        for(let i in arrTemp){
            let num = parseInt(arr[i]);
            // console.log(num)
            for(let j=0;j<num;j++){
              sArr.push(arrTemp[i]);
            }
        }

        // console.log("==============================")
        // console.log(sArr)
        // console.log("==============================")

        var serialNumber='';
        var arrs = sArr;
        var res = []; //
        // arrs.sort();
        for (var i = 0; i < arrs.length;) {
            var count = 0;
            for (var j = i; j < arrs.length; j++) {
                if (arrs[i] == arrs[j]) {
                    count++;
                }
            }
            res.push([arrs[i], count]);
            i += count;
        }
        //_res 二维数维中保存了 值和值的重复数
        var newArr = [];
        for (var i = 0; i < res.length; i++) {
            // console.log(res[i][0] + "重复次数:" + res[i][1]);
            newArr.push(res[i][0] + '*' + res[i][1]);
        }
        // console.log(arrTemps);
        // console.log(arr);
        serialNumber = newArr.join(",");
        return serialNumber;
      }

    },
    closing(data) { // yyyy-MM-dd hh:mm:ss
      if (data==0){
        return "未结算";
        }else{
          return "已结算";
        }

    },
    closings(data) { // yyyy-MM-dd hh:mm:ss
      if (data==0){
        return "未支付";
        }else{
          return "已支付";
        }
    },
    orderStatus(data){
      if (data==0){
        return "未开始";
        }else if(data==1){
          return "已完成";
        }else{
          return "进行中";
        }
    },
    num(nums,productTypeId,numList){
      if(util.isEmpty(productTypeId)){
        return numList;
      }
      if(!util.isEmpty(productTypeId)){
      let arrTemp = productTypeId.split(",");
      let m = 0;
      arrTemp = arrTemp.map(Number);

      for(var i=0;i<arrTemp.length;i++){
        if(arrTemp[i]==2){
          m = m+1
        }
      }
      return nums-m;
      }
    },

    priceCost(priceCost,amount,interiorAmount){
      return parseFloat(priceCost+amount+interiorAmount).toFixed(2);
    },

    payPriceCost(priceCost,payPriceCost,amount,interiorAmount){
      if(payPriceCost==null||payPriceCost==0){
        return parseFloat(priceCost+amount+interiorAmount).toFixed(2);
      }else{
        return parseFloat(payPriceCost).toFixed(2);
      }
    },

    payPrice(price,amountPay,note,interiorAmountPay){
      if(this.userRole != 8){
        return parseFloat(price+amountPay+interiorAmountPay).toFixed(2);
      }
      return note;

    },

    submitFormExcle() {
      //this.editForm.next = 0;
      if(this.editForm.id == 0){
        this.saveOrNext();
      }else{
        this.updateOrderPrice();
      }


    },



    submitForm() {


      if(util.isEmpty(this.editForm.testTasks)){
        this.$message.error('请选增加检测任务');
        return;
      }

      //公告：ABCDEFGHIK 1
      //达标：ABCDEFGHJKLMN 2
      //CCC：ABCDEFKG 3
      //环保：ABCDEFK 4
      //其他：ABCDEFKO 19
      switch(this.editForm.productTypeId1){
        case 1:
          if(util.isEmpty(this.editForm.a)
            || util.isEmpty(this.editForm.b)
            || util.isEmpty(this.editForm.c)
            || util.isEmpty(this.editForm.d)
            || util.isEmpty(this.editForm.e)
            || util.isEmpty(this.editForm.f)
            || util.isEmpty(this.editForm.g)
            || util.isEmpty(this.editForm.h)
            || util.isEmpty(this.editForm.i)
            || util.isEmpty(this.editForm.k)){
            this.$message.error('请选择检测工程师');
            return;
          }
          break;
        case 2:
          if(util.isEmpty(this.editForm.a)
            || util.isEmpty(this.editForm.b)
            || util.isEmpty(this.editForm.c)
            || util.isEmpty(this.editForm.d)
            || util.isEmpty(this.editForm.e)
            || util.isEmpty(this.editForm.f)
            || util.isEmpty(this.editForm.g)
            || util.isEmpty(this.editForm.h)
            || util.isEmpty(this.editForm.j)
            || util.isEmpty(this.editForm.k)
            || util.isEmpty(this.editForm.l)
            || util.isEmpty(this.editForm.m)
            || util.isEmpty(this.editForm.n)){
            this.$message.error('请选择检测工程师');
            return;
          }
          break;
        case 3:

          if(util.isEmpty(this.editForm.a)
            || util.isEmpty(this.editForm.b)
            || util.isEmpty(this.editForm.c)
            || util.isEmpty(this.editForm.d)
            || util.isEmpty(this.editForm.e)
            || util.isEmpty(this.editForm.f)
            || util.isEmpty(this.editForm.k)
            || util.isEmpty(this.editForm.g)){
            this.$message.error('请选择检测工程师');
            return;
          }
          break;
        case 4:

          if(util.isEmpty(this.editForm.a)
            || util.isEmpty(this.editForm.b)
            || util.isEmpty(this.editForm.c)
            || util.isEmpty(this.editForm.d)
            || util.isEmpty(this.editForm.e)
            || util.isEmpty(this.editForm.f)
            || util.isEmpty(this.editForm.k)){
            this.$message.error('请选择检测工程师');
            return;
          }
          break;
        case 19:
          if(util.isEmpty(this.editForm.a)
            || util.isEmpty(this.editForm.b)
            || util.isEmpty(this.editForm.c)
            || util.isEmpty(this.editForm.d)
            || util.isEmpty(this.editForm.e)
            || util.isEmpty(this.editForm.f)
            || util.isEmpty(this.editForm.k)
            || util.isEmpty(this.editForm.o)){
            this.$message.error('请选择检测工程师');
            return;
          }
          break;
      }
      //this.editForm.next = 0;
      if(this.editForm.id == 0){
        this.saveOrNext();
      }else{
        this.updateOrderPrice();
      }

    },
    updateOrderPrice(){
      const loadingDiv = util.showLoading("保存中")
      this.loading = true;
      updateOrderPrice(this.editForm).then(res => {
        if(res.code == 0) {
          this.$alert(res.msg, "保存失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "保存成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(()=> {
              this.editFormVisible=false;
              this.excleVisible = false;
              this.getDataList(this.currentPage)
            })
        }
        this.loading = false;
        loadingDiv.close();
      }).catch(res => {
        this.loading = false;
        loadingDiv.close();
      })
    },
    submitFormNext() {
      this.editForm.next = 1;
      this.saveOrNext();
    },

    saveOrNext(){

      this.$refs.editForm.validate(valid => {
        if(valid) {
          this.loading = true;
          let loadingText = "保存中...";
          if(this.editForm.next == 1){
            loadingText = "下发中...";
          }
          const loadingDiv = util.showLoading(loadingText)
          saveOrNextTestOrder(this.editForm).then(res => {
            let title = "保存"
            if(this.editForm.next == 1){
              title = "下发"
            }
            if(res.code == 0) {
              this.$alert(res.msg, title+"失败", {dangerouslyUseHTMLString:true,type:'warning'})
            }else if(res.code == 1) {
              this.$alert(res.msg, title+"成功", {dangerouslyUseHTMLString:true,type:'success'})
                .then(()=> {
                  this.editFormVisible=false;
                  this.getDataList(this.currentPage)
                })
            }
            this.loading = false;
            loadingDiv.close();
          }).catch(res => {
            this.loading = false;
            loadingDiv.close();
          })
        }
      });
    },

    clear(){
      for(let key in this.searchForm){
        this.searchForm[key]  = ''
      }
      for(let key in this.date){
        this.date[key]  = ''
      }
      this.searchForm.userTypeIdList = [1,2,3,4,5,6];
      this.searchForm.orderStatus = 2;
      this.getDataList(this.currentPage);
    },

    handleDelete(index, row) {
      let loadingDiv;
      this.$confirm("是否确认删除?","删除确认").then(res=>{
        if(res='confirm'){
          loadingDiv = util.showLoading("删除中...")
          return deleteTestOrder({tOrderId: row.tOrderId})
        }
      }).then(res => {
        loadingDiv.close();
        if(res.code == 0) {
          this.$alert(res.msg, "删除失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "删除成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(res=>{
              this.editFormVisible=false;
              this.getDataList(this.currentPage)
            })
        }
      }).catch(res=>{
        if (loadingDiv){
          loadingDiv.close();
        }
      })
    },

    handleTaskDone(index, row){

      getTaskItemsCarAndLogsId({tOrderId:row.tOrderId}).then(res=>{
        // console.log(res)
        if(res.code == 1){
          this.taskItems = res.data.taskItems;
          this.doneTaskItems = res.data.doneTaskItems;

          let arr = [];
          if(!util.isEmpty(this.doneTaskItems)){
            for(let i in this.doneTaskItems){
              arr.push(this.doneTaskItems[i].orderTaskItemCarId)
            }
          }
          this.doneForm.carId = row.id;
          this.doneForm.doneTaskItemIds = arr;
          this.doneRow = row;

          this.doneFormVisible=true;
        }else{
          this.$message.error("加载信息失败")
        }
      });
    },


    getDataList(pageNum){
      const loadingDiv = util.showLoading()
      getUserRole().then(res => {
        if(res.code == 0) {
          this.$message({
            showClose: true,
            message: res.msg,
            type: 'error'
          });
        }else if(res.code == 1) {
          let data = res.data;
          this.userRole = data.userRole
          // console.log(this.userRole)

        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      });

      getTestOrderAllList({
        pageSize: this.pageSize,
        pageNum: pageNum,
        orderStatus: this.searchForm.orderStatus,
        carEnterpriseId: this.searchForm.carEnterpriseId,
        carTypeId: this.searchForm.carTypeId,
        productTypeIds: this.searchForm.productTypeIds,
        customerName: this.searchForm.customerName,
        closingPayPrice: this.searchForm.closingPayPrice,
        closingCost: this.searchForm.closingCost,
      }).then(res => {
        if(res.code == 0) {
          this.$message({
            showClose: true,
            message: res.msg,
            type: 'error'
          });
        }else if(res.code == 1) {
          let data = res.data;
          this.currentPage = pageNum;
          this.total = data.total;
          this.tableData = data.dataList;
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },
    search() {
      this.getDataList(this.currentPage)
    },
    handleSizeChange(pageSize) {
            this.pageSize = pageSize;
            this.getDataList(1)
          },
    handleCurrentChange(pageNum) {
            this.getDataList(pageNum);
          },
    handlePriceOtherManage(index, row){
      let item = {
        componentName:"priceOtherManage",
        icon:"",
        path:"/task/price_other_manage/"+row.tOrderId,
        title: "其他费用管理",
      };

      this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}})
    },
    updateLog(index, row){
      let item = {
        componentName:"updateLog",
        icon:"",
        path:"/task/update_log/"+row.tOrderId,
        title: "操作日志",
      };

      this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}})
    },
    handleOrderTask(index, row){
      // let item = {
      //   componentName:"testOrderTaskManage",
      //   icon:"",
      //   path:"/task/test_order_task_manage/"+row.tOrderId,
      //   title: "任务下发",
      // };

      // this.$store.commit("openTab",{item:item, router: (path)=>{this.$router.replace(path)}})

    },
  }
}
</script>

<style scoped lang="scss">
  // @import "~@/common/styles/element-variables.scss";
  .search-box {
    background-color: #FFFFFF;
    min-height: 36px;
    line-height: 36px;
    padding-top: 2px;
    padding-bottom: 6px;
    .el-form-item {
      margin-bottom: 0px !important;
    }
    .el-form--inline {
      display: inline-block;
    }
  }
  .pagination-box {
    text-align: left;
    margin-top: 10px;
  }
  .test-item-table{
    width: 100%;
    border-collapse: collapse;

    th, td {
      width: 7%;
      text-align: center;
      border: 1px solid #CCC;
    }
    th {
      background-color: #EDF2FC;
    }
  }
  .chose-role{
    display: inline-block;
    margin-left: 20px;
    margin-bottom: 20px;
  }
</style>
<style lang="scss">
  .el-dialog__header {

  }
  .el-dialog__body {
    padding-top: 10px;
    padding-bottom: 0px;
  }
  .el-dialog__footer {
    padding-top: 0px;
  }
</style>
